// GemTermCE.cpp : main source file for GemTermCE.exe
//

#include "stdafx.h"

#include "resource.h"

#include "aboutdlg.h"
#include "MainDlg.h"

#ifdef DEBUG
DBGPARAM dpCurSettings = {
     TEXT("GemTerm"), {
     TEXT("Port"),TEXT("Registry"),TEXT("TAPI"),TEXT("Unused"),
     TEXT("Unused"),TEXT("Unused"),TEXT("Unused"),TEXT("Unused"),
     TEXT("Unused"),TEXT("Unused"),TEXT("Unused"),TEXT("Misc"),
     TEXT("Alloc"),TEXT("Function"),TEXT("Warning"),TEXT("Error") },
     0x0000ffff
}; 
#endif   // DEBUG

CAppModule _Module;

int Run(LPTSTR /*lpstrCmdLine*/ = NULL, int nCmdShow = SW_SHOWNORMAL)
{
	CMessageLoop theLoop;
	_Module.AddMessageLoop(&theLoop);

	CMainDlg dlgMain;

	if(dlgMain.Create(NULL) == NULL)
	{
		ATLTRACE(_T("Main dialog creation failed!\n"));
		return 0;
	}

	dlgMain.ShowWindow(nCmdShow);

	int nRet = theLoop.Run();

	_Module.RemoveMessageLoop();
	return nRet;
}

int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow)
{
	//HRESULT hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
	//ATLASSERT(SUCCEEDED(hRes));

	// Register Zones
    //DEBUGREGISTER(NULL);

	// This is for CE6 ModuleHelper::GetResourceInstance() BUG
	// Otherwise, all of the resource loading will fail in CE6
	ATL::_AtlBaseModule.SetResourceInstance(hInstance);

	// Calling AtlInitCommonControls is not necessary to utilize picture,
	// static text, edit box, group box, button, check box, radio button, 
	// combo box, list box, or the horizontal and vertical scroll bars.
	// Calling AtlInitCommonControls with 0 is required to utilize the spin, 
	// progress, slider, list, tree, and tab controls.
	// Adding the ICC_DATE_CLASSES flag is required to initialize the 
	// date time picker and month calendar controls.
	// Add additional flags to support additoinal controls not mentioned above.
	AtlInitCommonControls(ICC_DATE_CLASSES);

	HRESULT hRes = _Module.Init(NULL, hInstance);
	ATLASSERT(SUCCEEDED(hRes));

	int nRet = Run(lpstrCmdLine, nCmdShow);

	_Module.Term();
	//::CoUninitialize();

	return nRet;
}
